<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<jsp:include page="../ueditor.jsp"></jsp:include>
<%@page import="com.sdry.entity.base.Staff"%>
<%
	String path=request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh">
<head>
	<style>
		.combo .combo-text {
	    	font-size: 20px;
	    }
	   .datagrid-cell-rownumber {
		    height: 25px;
		    line-height: 25px;
		    font-size: 20px;
		}
	    
		table.table-edit tr td{
			text-align:center;
			vertical-align:middle;
			font-size: 20px;
		}
		table.table-edit tr{border-bottom:1px white solid;}
		table.table-edit tr.title {
			background-color: #EAEAEA4D;
		}
		table.table-edit tr.title td{
			font-size: 30px;
		}
		.combo .combo-text {
    		font-size: 18px;
    	}
    	.datagrid-cell-rownumber {
		    height: 25px;
		    line-height: 25px;
		    font-size: 16px;
		}
    	.datagrid-cell{
		    height: 25px;
		    line-height: 25px;
		    font-size: 16px;
		}
		/*边框颜色*/
		input[type="text"], input[type="password"], textarea {
			border: 1px solid #DEE4EA99;
		}
		/*去掉点击是出现的验证红框*/
		.focus, input:focus, select:focus, textarea:focus {
			outline: 1px solid #f000;
		}
		/*初始化编辑器高度,默认320*/
	    #edui1_iframeholder{
	        height: 67vh !important
	    }
      .selectIten {
       		width: 65% ; 
       }
       
	</style>
	<%
		Staff staff = (Staff)session.getAttribute("staff");
		String d = null;
		if(staff != null){
		  d = staff.getSreserve1();
		}
	%>
</head>
<body style="background-color: #ffffff;">
<div class="page-content-iframe">
	<div region="center">
		<form id="fm">
			<table class="table-edit" width="99%" align="center" style="min-width: 1235px">
				<tr class="title">
					<td colspan="3">
						文档编辑
						<div style="width: 200px;margin-top: -33px;margin-left: 80%;margin-right: 0px;">
							<a icon="icon-back" class="easyui-linkbutton" plain="true" onclick="history.go(-1)">返回</a>
							&nbsp;&nbsp;
							<a icon="icon-save" class="easyui-linkbutton" plain="true" onclick="save()">保存</a>
							&nbsp;&nbsp;&nbsp;
							<%-- <a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="go1()">简版填写（根据“？？？”精简）</a>
							&nbsp;&nbsp;
							<a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="go2()">还原</a>
							&nbsp;&nbsp;
							<a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="insertHtml()">签字</a>
							<input type="hidden" id="d" value="<%=d%>"> --%>
						</div>
					</td>
				</tr>
				<tr></tr>
				<tr>
					<td colspan="2" style="text-align: left;">
						文档标题:
						<textarea type="text" id="aname" name="aname"  placeholder="请输入标题" class="easyui-validatebox"  data-options="required:true" validType="aname" style="width:400px;height: 28px;font-size: 18px;border: 1px solid #95b8e7;">${agreement.aname}</textarea>
					</td>
					<td style="text-align: left;">
						文档类别:
						<select id="client" name="client"  class="easyui-combobox" data-options="required:true" editable="false" style="width: 300px;Height:28px;">
						</select>
						<script type="text/javascript">
							$(function(){	
								$.ajax({
						            url: '/type/selectAll.do' ,
						            type: 'post',
						            async:false,
						            dataType:'json',
						            success: function (data) {
						            	 var datas = [];
						                //设置下拉列表中的值的属性
						                for ( var i = 0; i < data.length; i++) {
						              	  	datas.push({"text":data[i].tname,"value":data[i].id});
										 }
						                $("#client").combobox("loadData",datas);////此时我们便将所有option添加到select中了
						                var cid = '${agreement.client}';
										if(cid != "" && cid != null){
											$("#client").combobox("setValue",cid);
										}else{
											$("#client").combobox("setValue",data[0].id);
										}
						            },
						        });
					        });
							
						</script>
						<input type="hidden" id="aid" name="aid" value="${agreement.aid}">
						<input type="hidden" id="aremark3" name="aremark3">
						<input type="hidden" id="aremark1" name="aremark1">
						<input type="hidden" id="tremark3" name="tremark3">
					</td>
				</tr>
				<tr>
					<td style="text-align: left;">
						所属项目: 
						<select class="selectIten" id="itemA" name="itemA" style="width: 300px;Height:28px;">
						</select>
						<script type="text/javascript">
						$(function(){
							/* *************************** */
							//工种下拉框添加
							$('#itemA').combogrid({  
								toolbar: [{
			                        text: "归属名称 <input  type=\"text\" id=\"titleA\"></input>",  
								},'-',{
									iconCls: 'icon-search',
									handler: function(){
										$('#itemA').combogrid('grid').datagrid('reload',{  
											title:$.trim($('#titleA').val()),  
									        }  
									     ); 
									}
								}],
								queryParams:{title:''}, 
								panelWidth:700,
								panelHeight:350,
								idField: 'ID',
								editable:false,
								textField: 'title',
								loadMsg: '正在拼命加载,请稍后...',
								striped: true,       //交替条纹
								url: '${pageContext.request.contextPath }/aProjectBase/selectASpecialBase.do',
								fitColumns: true,  
								singleSelect:false,	//设置为 true，则只允许选中一行。
								fit: true,         //自动大小 
								pagination : false,//是否分页  
								rownumbers:true,//序号
								pageSize: 5,//每页显示的记录条数，默认为10  
								pageList: [5,10,15],//可以设置每页记录条数的列表  
								method:'post',
								columns: [[
									{field:'ID',title:'ID',width:80,hidden:true},
									{field:'title',title:'归属名称',width:80,align:'left', halign: 'center'},
									{field:'alias',title:'归属简称',width:80,align:'left', halign: 'center'},
									{field:'code',title:'归属编码',width:80,align:'center'},
								]],
								onClickRow : ssA
							});
						});
						
						
						function ssA(rowIndex, rowData) {
							selectB($('#itemA').combogrid('getValue'))
						}
						</script>
						<input type="hidden" id="item" name="item" value="${agreement.item}">
					</td>
				<!-- </tr>
				<tr> -->
					<td style="text-align: left;">
						专项基金:
						<select class="selectIten" id="itemB" name="itemB" style="width: 300px;Height:28px;">
						</select>
						<script type="text/javascript">
						$(function(){
							/* *************************** */
							//工种下拉框添加
							$('#itemB').combogrid({  
								toolbar: [{
			                        text: "项目名称 <input  type=\"text\" id=\"titleB\"></input>",  
								},'-',{
									iconCls: 'icon-search',
									handler: function(){
										var idA = $('#itemA').combogrid('getValue')
										if(idA == "" || idA == null){
											idA = 0
										}
										$('#itemB').combogrid('grid').datagrid('reload',{  
											title:$.trim($('#titleB').val()),  
											id:idA,  
									    }); 
									}
								}],
								queryParams:{id:0}, 
								panelWidth:700,
								panelHeight:350,
								idField: 'ID',
								editable:false,
								textField: 'title',
								loadMsg: '正在拼命加载,请稍后...',
								striped: true,       //交替条纹
								url: '${pageContext.request.contextPath }/aProjectBase/selectAProjectBase.do',
								fitColumns: true,  
								singleSelect:false,	//设置为 true，则只允许选中一行。
								fit: true,         //自动大小 
								pagination : false,//是否分页  
								rownumbers:true,//序号
								pageSize: 5,//每页显示的记录条数，默认为10  
								pageList: [5,10,15],//可以设置每页记录条数的列表  
								method:'post',
								columns: [[
									{field:'ID',title:'ID',width:80,hidden:true},
									{field:'title',title:'项目名称',width:80,align:'left', halign: 'center'},
									{field:'alias',title:'项目简称',width:80,align:'left', halign: 'center'},
									{field:'code',title:'归属编码',width:80,align:'center'},
								]],
								onClickRow : ssB
							});
						});
						
						
						function ssB(rowIndex, rowData) {
							selectC($('#itemB').combogrid('getValue'))
						}
						</script>
					</td>
				<!-- </tr>
				<tr> -->
					<td style="text-align: left;">
						活动名称:
						<select class="selectIten" id="itemC" name="itemC" style="width: 300px;Height:28px;">
						</select>
						<script type="text/javascript">
						$(function(){
							/* *************************** */
							//工种下拉框添加
							$('#itemC').combogrid({  
								toolbar: [{
			                        text: "活动名称 <input  type=\"text\" id=\"titleC\"></input>",  
								},'-',{
									iconCls: 'icon-search',
									handler: function(){
										var idB = $('#itemB').combogrid('getValue')
										if(idB == "" || idB == null){
											idB = 0
										}
										$('#itemC').combogrid('grid').datagrid('reload',{  
											title:$.trim($('#titleC').val()),  
											id:idB,  
									        }  
									     ); 
									}
								}],
								queryParams:{id:0}, 
								//panelWidth:300,
								panelHeight:350,
								//idField: 'ID',
								editable:false,
								textField: 'title',
								loadMsg: '正在拼命加载,请稍后...',
								striped: true,       //交替条纹
								url: '${pageContext.request.contextPath }/aProjectBase/selectAProjectActivity.do',
								fitColumns: true,  
								singleSelect:false,	//设置为 true，则只允许选中一行。
								fit: true,         //自动大小 
								pagination : false,//是否分页  
								rownumbers:true,//序号
								pageSize: 5,//每页显示的记录条数，默认为10  
								pageList: [5,10,15],//可以设置每页记录条数的列表  
								method:'post',
								columns: [[
									{field:'ID',title:'ID',width:80,hidden:true},
									{field:'title',title:'活动名称',width:80,align:'left', halign: 'center'},
									/* {field:'alias',title:'归属简称',width:80,align:'center'},
									{field:'code',title:'归属编码',width:80,align:'center'}, */
								]],
								//onClickRow : ssC
							});
						});
						</script>
					</td>
				</tr>
				<tr></tr>
				<%-- <tr>
					<td colspan="4" style="text-align:right;">
						<a icon="icon-back" class="easyui-linkbutton" plain="true" onclick="history.go(-1)">返回</a>
						&nbsp;&nbsp;
						<a icon="icon-save" class="easyui-linkbutton" plain="true" onclick="save()">保存</a>
						&nbsp;&nbsp;&nbsp;
						<a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="go1()">简版填写（根据“？？？”精简）</a>
						&nbsp;&nbsp;
						<a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="go2()">还原</a>
						&nbsp;&nbsp;
						<a icon="icon-edit" class="easyui-linkbutton" plain="true" onclick="insertHtml()">签字</a>
						<input type="hidden" id="d" value="<%=d%>">
					</td>
				</tr> --%>
			</table>
			<div>
				<textarea id="html" name="html" style="min-width: 1235px;"></textarea>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	//是否执行修改操作标识
	var editFlg = false;
	
	//是否执行保存操作标识
	var addFlg = false;
	//监听内容改变事件
	ue.addListener("contentChange",function(){
		//ueditorUE 取值
	    var data = ue.getContent();
	    var d = "display: none;";
		var str1 = data.split(d);
	    //没有隐藏数据
	    if(str1.length == 1 && data != null && data != "" && addFlg == false){
	    	if(!editFlg){
		    	bd();
		    }else{
		    	editFlg = false;
		    }
	        go1(); 
		}
	});
	//签名
	var d = $.trim($('#d').val());
	function insertHtml() {
		if(d != null && d != ""){
			var value = "<img src = 'http://localhost:8000/"+d+"'/>"
		    ue.execCommand('insertHtml', value)
		}else{
			toastr.warning('没有查到当前用户的签名图片！');
		}
	}
	$(function(){
		//页面加载时设置所有的<input>和<textArea>标签隐藏
		for (var i = 0; i <= 20; i++) {
			$("#"+i).hide();
			$("#t"+i).hide();
		}
		//页面加载查询所有部门
		/* $.ajax({
	        type: 'POST',
	        url: '${pageContext.request.contextPath}/approval/queryAllDept.do',
	        dataType: 'json',
	        success: function (data){
	            for (var i = 0; i < data.length; i++) {
	                $("#dept").append("<option value='"+ data[i].dname +"'>"+ data[i].dname +"</option>");
	            }
	            var res='';
	            var count = 0;
	            $("#dept").on("click",function(){
	            	count ++;
	            	res += $(this).val()+'—>';
	            	$("#appendDept").val(res);
	            	$("#dept option:selected").attr("disabled", true);
	            	if (count == 4) {
	            		$("#dept").attr("disabled", true);
					}
	    		})
	        }
	    }); */
		
	    
		
		
		
		//修改时给文本框赋值
		var item = $.trim($('#item').val());
		if(item != null && item != ""){
			var items =item.split(",");
			if (items.length >= 5) {
				if(items[0] != null && items[0] != ""){
					$("#itemA").combogrid("setValue",items[0]);
					selectB(items[0]);
					if(items[2] != null && items[2] != ""){
						$("#itemB").combogrid("setValue",items[2]);
						selectC(items[2]);
						if(items[4] != null && items[4] != ""){
							$("#itemC").combogrid("setValue",items[4]);
						}
					}
				}
			}
		}
		
	});
	
	//保存时获取三个选择框的值组合而成的字符串
	function  saveItem() {
		var idA = $('#itemA').combogrid('getValue');
		var textA = $('#itemA').combogrid('getText');
		var idB = $('#itemB').combogrid('getValue');
		var textB = $('#itemB').combogrid('getText');
		var textC = $('#itemC').combogrid('getText');
		var item = idA+","+textA+","+idB+","+textB+","+textC;
		$('#item').val(item);
	}
	
	//根据itemA的id刷新itemB
	function selectB(id) {
		$('#itemB').combogrid('grid').datagrid('reload',{  
			id:id,  
	    }); 
	}
	//根据itemB的id刷新itemC
	function selectC(id) {
		$('#itemC').combogrid('grid').datagrid('reload',{  
			id:id,  
	    }); 
	}
	
	//修改时根据id赋值文本框
    var aid = $.trim($('#aid').val());
	ue.addListener("ready", function () {
		if(aid != null && aid != ""){
			//赋值
	        $.ajax({
	            url: '/agreement/selectAgreementById.do' ,
	            type: 'post',
	            async:false,
	            dataType:'json',
	            data:"id="+aid,
	            success: function (data) {
	            	editFlg = true;
	            	ue.setContent(data.html);
	                //textModify()
	                //表单内容
					var arrS = data.aremark3;
					var arr = arrS.split(";");
	                var data1 = arr[0];
	                var data2 = arr[1];
	                var data11 = data.aremark1;
	                $('#aremark3').val(data1);
					//对应表单
					$('#aremark1').val(data11);
					$('#tremark3').val(data2);
					//文本框名称
					var arr1 = data1.split(",");
					var arr11 = data11.split(",");
					//文本框类型
					var arr2 = data2.split(",");
					for (var i = 0; i < arr1.length; i++) {
						//alert(arr.length);
						//如果文本框类型为2,则显示多行文本框
						//debugger;
						if (arr2[i]=='2') {
							//label标签赋值显示
							$("#b"+i).html(arr1[i]);
							$("#t"+i).show();
							$('#t'+i).val(arr11[i]);
						} else {
							//label标签赋值显示
							$("#a"+i).html(arr1[i]);
							//如果文本框类型为1,则显示文本框
							$("#"+i).show();
							$('#'+i).val(arr11[i])
						}
					}
	            },
	        });
		}else{
			ue.setContent("<p style='display: none;'></p>");
		}
    });

    //扩展validatebox，添加验证两次密码功能
    //密码验证
    $.extend($.fn.validatebox.defaults.rules, {
        aname: { //验证手机号
            validator: function(value, param){
                var success = false;
				var checkR=$.ajax({
                    async : false,
                    cache : false,
                    type : 'post',
                    url: '${pageContext.request.contextPath}/agreement/selectAgreementByExample.do',
                    data : {
                    	aname:value
                    }
                }).responseText;
                var dataObj=eval("("+checkR+")");//转换为json对象
                if(aid != '' && aid != null){
                    if(dataObj.length == 1 && dataObj[0].aid == aid){
                        success= true;
                    }else if(dataObj.length == 0){
                        success= true;
                    }
                }else{
                    if(dataObj.length == 0){
                        success= true;
					}
				}
                return success==true;
            },
            message: '标题不能重复'
        },
        
        currency: {// 验证货币
	        validator: function (value) {
	            return /^\d+(\.\d+)?$/i.test(value);
	        },
	        message: '货币格式不正确'
	    }, 
    });
	//保存
    function bd() {
    	var data = ue.getContent();
		var idq = "<input id=\"tid\"";
        var idh = "\"/>";
        
		var idq1 = "value=\"";
        var idh1 = "**";
        
        var id1 = data.split(idq);
        var id2 = id1[1].split(idh);
        var id = id2[0];
        
        var idv = id.split(idq1);
        var idx = idv[1].split(idh1);
        var idz = idx[0];
        for (var i = 0; i <= 20; i++) {
			$("#"+i).hide();
			$("#"+i).val('');
			document.getElementById('a'+i).innerText='';
			$("#t"+i).hide();
			$("#t"+i).val('');
			document.getElementById('b'+i).innerText='';
		}
        $.ajax({
	        type: 'POST',
	        url: '${pageContext.request.contextPath}/template/selectTemplateById.do',
	        dataType: 'json',
	        data:"id="+idz,
	        success: function (data){
	        	var data1 = data.tremark;
				//字段类型
	        	var data2 = data.tremark3;
	        	if(data1 != null && data1 != ""){
					$('#aremark3').val(data1);
					$('#tremark3').val(data2);
					//文本框名称
					var arr1 = data1.split(",");
					//文本框类型
					var arr2 = data2.split(",");
					for (var i = 0; i < arr1.length; i++) {
						//alert(arr.length);
						//如果文本框类型为2,则显示多行文本框
						//debugger;
						if (arr2[i]=='2') {
							//label标签赋值显示
							$("#b"+i).html(arr1[i]);
							$("#t"+i).show();
						} else {
							//label标签赋值显示
							$("#a"+i).html(arr1[i]);
							//如果文本框类型为1,则显示文本框
							$("#"+i).show();
						}
					}
				}
	        }
	    });
	}
	
	var data1 = "";
	function inputSave(){
		var data = $.trim($('#aremark3').val());
		var datas = $.trim($('#tremark3').val());
       	var datasArr = datas.split(",");
        for (var i = 0; i < datasArr.length; i++) {
           	if(i == 0){
           		if (datasArr[i] == '2') {
           			data1 = data1 + $.trim($('#t'+i).val());
   				} else {
   					data1 = data1 + $.trim($('#'+i).val());
   				}
           	}else{
           		if (datasArr[i] == '2') {
           			data1 = data1 + "," + $.trim($('#t'+i).val());
           		} else {
           			data1 = data1 + "," + $.trim($('#'+i).val());
           		}
           	}
       	}
       	$('#aremark1').val(data1);
       	$('#aremark3').val(data +";"+ datas);
	}
	 //**************************************************************** 
  	 //* 名　　称：DataLength 
     //* 功    能：计算数据的长度 
     //* 入口参数：fData：需要计算的数据 
     //* 出口参数：返回fData的长度(Unicode长度为2，非Unicode长度为1) 
    //***************************************************************** 
    function DataLength(fData) 
    { 
        var intLength=0 
        for (var i=0;i<fData.length;i++) 
        { 
            if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)){
                //intLength=intLength+2 
                intLength=intLength+1 
            } 
            //else 
                //intLength=intLength+1    
        } 
        return intLength 
    } 
	//保存
    function save() {
        if (addFlg ==true) {
            return false;
        }

        if ($("#fm").form("validate")==false) {
            return false;
        }
        var aname = $.trim($("#aname").val());
        var intLengthAname = DataLength(aname);
        if(intLengthAname < 20){
        	toastr.warning("标题少于20个汉字！");
        }
        addFlg  =  true;
        saveItem();
        go2();
		inputSave();
        // 添加审批人顺序
		/* $.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/approval/insertDept.do",
			data : {"aname":$("#aname").val(), "appendDept":$("#appendDept").val()},
			//processData:false,
            //contentType:false,
            async:false,
			success : function(data) {
				if(data > 0) {
					$("#aremark").val(data); */
					//添加
			        var  url = "${pageContext.request.contextPath}/agreement/insertAgreement.do";
					var title = "新增";
			        if(aid != '' && aid != null){
			            //修改
						url = "${pageContext.request.contextPath}/agreement/editAgreement.do";
			            title = "修改";
					}
			        $.ajax({
			            url: url ,
			            type: 'post',
			            data:$("#fm").serialize(),
			            async:false,
			            success: function (data1) {
			                if (data1 == 1) {
			            		//如果文档类型是表单则根据表单内容获取信息保存至单据统计
			                	/* var client = $('#client').combobox('getText');
			            		var fg = 0;
			            		var ht = ue.getContent();
			                   	if(ht != "" || ht != null){
				                   	var arr = ht.split("汇款领用单");
				                   	var arr1 = ht.split("支票领用单");
				                   	if(arr.length > 1){
				                   		fg = 1;
				                   	}
				                   	if(arr1.length > 1){
				                   		fg = 1;
				                   	}
			                   	}
			            		if(client == "表单" && fg == 1){
			            			var aid = findIdByAname();
			                		if(saveBillForm(aid)){
			                			toastr.success(title+'成功')
										//$.messager.alert("系统提示",title+'成功');
										addFlg = false;
					                    setTimeout("go()",1000);
			                		}
			                	}else{
				                	 toastr.success(title+'成功')
									//$.messager.alert("系统提示",title+'成功');
									addFlg = false;
				                    setTimeout("go()",1000);
			                	} */
			                	toastr.success(title+'成功')
			                	addFlg = false;
			                    setTimeout("go()",1000);
			                } else {
			                	toastr.error(title+'失败')
			                    //$.messager.alert("系统提示",title+'失败');
			                    addFlg  =  false
			                }
			            },
			        });
					//alert($("#aremark").val())
					//toastr.success('提交申请成功！');
					//$("#clean").click();
					//location.reload();
					//setTimeout("go()",1000);
				/* } else {
					toastr.warning('提交申请出现错误！');
				}
			},
			error : function () {
				toastr.error('提交申请失败！');
			}
		}); */
    }
  	//简化废弃
    /* function go1() {
        //ueditorUE 取值
        var data = ue.getContent();
        var sp = "<p style=\"";
        var str = data.split(sp);
        var html = "";
		var d = "display: none;";
        //显示所在行的内容
		var h = "？？？"
        for (var i=0;i<str.length;i++) {
        	//出现
		    if(str[i].indexOf(h) != -1){
                html = html + sp + str[i];
			}else {
		        if(i != 0){
                	html = html + sp + d + str[i];
				}
			}
        }
        ue.setContent(html);
    } */
    //获取俩字符中相同字段
	function getMaxStr(str1,str2){
        var max = str1.length > str2.length ? str1 : str2;
        var min = (max == str1 ? str2 : str1);
        for(var i = 0; i < min.length; i++){
            for(var x = 0, y = min.length - i;y != min.length + 1;x++,y++){
                //y表示所取字符串的长度
                var newStr = min.substring(x,y);
                //判断max中是否包含newStr
                if(max.indexOf(newStr) != -1){
                    return newStr;
                }
            }
        }
        return -1;
    }

    function hangGl(data,s,h,yh,h1){
        //标签头+style
        var sp = "<"+s+" style=\"";
        //返回数据
        var html = "";
        var d = "display: none;";
        //标签头
        var p = "<"+s
		//标签尾
        var pjs = "</"+s+">"
        //标签头分组
        var str2 = data.split(p);
        //标签尾分组
        var strjs = data.split(pjs);
            for (var i=0;i<str2.length;i++) {
                if(i != 0){
                    //获取相同值
                    var ss = getMaxStr(str2[i], strjs[i-1].split(p)[1])
                    //出现
                    if (ss.indexOf(h) != -1 || ss.indexOf(yh) != -1 || ss.indexOf(h1) != -1) {
                        html = html + p + str2[i];
                    } else {
                        if (i != 0) {
                            var ssp = p+str2[i];
                            if(ssp.indexOf(sp) != -1){
                                html = html + sp + d + ssp.split(sp)[1];
							}else{
                           	 	html = html + sp + d + "\"" + str2[i];
							}
                        }
                    }
                }else{
					html = html + str2[i];
				}
            }
        return html;
    }
    function tableGl(data,s,h,yh,h1) {
        //返回数据
        var html = "";
        //标签头
        var tableq = "<"+s
		//标签尾
        var tableh = "</"+s+">"
        //标签头分组
        var strks = data.split(tableq);
        //标签尾分组
        var strjs = data.split(tableh);

        for (var i=0;i<strks.length;i++) {
            if(i == 0){
                html = html + hangGl(strks[i],"p",h,yh,h1);
            }else {
                //获取相同值
                var ss = getMaxStr(strks[i], strjs[i-1].split(tableq)[1])
                var qianHou = strks[i].split(ss);
				html = html + tableq + qianHou[0]+ss+ tableh+ hangGl(qianHou[1],"p",h,yh,h1);
            }
        }
        return html;
    }
	//简化
    function go1() {
    	var data = ue.getContent();
		//var h = "{[]}"
		var h = "{["
		var h1 = "]}"
		var yh = "^"
		var html = tableGl(data,"table",h,yh,h1);
		ue.setContent(html);
    }
	//简化
    function go1_back() {
    	var data = ue.getContent();
        var sp = "<p style=\"";
        var str = data.split(sp);
        var html = "";
		var d = "display: none;";
		var h = "？？？"
		var p = "<p"
        var str2 = data.split(p);
		if((str.length <= 1) && (str2.length >= 1)){

		    for (var i=0;i<str2.length;i++) {
                //出现
                if(str2[i].indexOf(h) != -1){
                    html = html + p + str2[i];
                }else {
                    if(i != 0){
                        html = html + sp + d + "\"" + str2[i];
                    }
                }
            }
		}else{
            for (var i=0;i<str.length;i++) {
                //出现
                if(str[i].indexOf(h) != -1){
                    html = html + sp + str[i];
                }else {
                    if(i != 0){
                        html = html + sp + d + str[i];
                    }
                }
            }
		}
		ue.setContent(html);
    }
    function go2() {
        var data = ue.getContent();
        var d = "display: none;";
        var items = data.split(d);
        data = items.join("");
        ue.setContent(data);
    }
    
    function go() {
        window.history.go(-1);
    }
    
    
    function add0(m){
    	var m1= Number(m)
    	return m1<10?'0'+m1:m1 
    }

    function findIdByAname() {
    	var aname = $.trim($("#aname").val());
        var aid = "";
    	$.ajax({
            url: '${pageContext.request.contextPath}/agreement/selectAgreementByExample.do',
            type: 'post',
            data:{"aname":aname},
            async:false,
            dataType:'json',
            success: function (data) {
            	if (data.length == 1) {
                	aid = data[0].aid;
            	}
            }
    	});
    	return aid;
    }
    function saveBillForm(aid) {
    	var fg = true;
       	var billFormName = "";
       	var billFormType = "";
       	var data = ue.getContent();
       	var arr = data.split("汇款领用单");
       	var num = 0;
       	if(arr.length > 1 ){
       		var arr1 = arr[1].split("</span>");
       		billFormType = "汇款领用单"+arr1[0];
       		if(billFormType != "汇款领用单（机关）"){
        		billFormName = tableHtmlnr(data,"table",1);
        		num = 1;
       		}
       	}else{
       		var zarr = data.split("支票领用单");
       		var zarr1 = zarr[1].split("</span>");
       		billFormType = "支票领用单"+zarr1[0];
       		
       	}
       	var year = tableHtmlnr(data,"table",num+1);
       	var month = tableHtmlnr(data,"table",num+2);
       	var day = tableHtmlnr(data,"table",num+3);
        var billFormTime=year+"-"+add0(month)+"-"+add0(day);
        var bfremark=tableHtmlnr(data,"table",num+4);
        var billFormItem=tableHtmlnr(data,"table",num+5);
        var billFormMoney=tableHtmlnr(data,"table",num+6);
       	$.ajax({
               url: "${pageContext.request.contextPath}/billForm/insertbillForm.do",
               type: 'post',
               data:{"aid":aid,"billFormName":billFormName
               	,"billFormType":billFormType
               	,"billFormTime":billFormTime
               	,"bfremark":bfremark
               	,"billFormItem":billFormItem
               	,"billFormMoney":billFormMoney},
               async:false,
               dataType:'json',
               success: function (data1) {
                   if (data1 == 1) {
                   } else {
                   	fg = false;
                   }
               },
           });
    	return fg;
    }
    
    
  	//把审批内容添加入呈批件内容（替换表格里第一个*）中
    function tableHtmlnr(data,s,num) {
        //返回数据
        var html = "";
        //标签头
        var tableq = "<"+s
    	//标签尾
        var tableh = "</"+s+">"
        //标签头分组
        var strks = data.split(tableq);
        //标签尾分组
        var strjs = data.split(tableh);

        for (var i=0;i<strks.length;i++) {
            if(i == 0){
                
            }else {
            	//获取相同值（table内容）
                var ss = getMaxStr(strks[i], strjs[i-1].split(tableq)[1])
                var qh = ss.split("{[");
                var hh = ss.split("]}");
                //第num个{[]}的内容
                html = getMaxStr(qh[num], hh[num-1].split("{[")[1])
                if(html == -1){
                	html = ""
                }
            }
        }
        return html;
    }
</script>
	<div style="margin-left: 70px">
		<!-- 文本框 -->
		<label id="a0" class="control-label leipiplugins-orgname" ></label><input type="text" id="0" style="margin-left: 10px; border: 1px solid gray">
		<label id="a1" class="control-label leipiplugins-orgname" ></label><input type="text" id="1" style="margin-left: 10px; border: 1px solid gray">
		<label id="a2" class="control-label leipiplugins-orgname" ></label><input type="text" id="2" style="margin-left: 10px; border: 1px solid gray">
		<label id="a3" class="control-label leipiplugins-orgname" ></label><input type="text" id="3" style="margin-left: 10px; border: 1px solid gray">
		<label id="a4" class="control-label leipiplugins-orgname" ></label><input type="text" id="4" style="margin-left: 10px; border: 1px solid gray">
		<label id="a5" class="control-label leipiplugins-orgname" ></label><input type="text" id="5" style="margin-left: 10px; border: 1px solid gray">
		<label id="a6" class="control-label leipiplugins-orgname" ></label><input type="text" id="6" style="margin-left: 10px; border: 1px solid gray">
		<label id="a7" class="control-label leipiplugins-orgname" ></label><input type="text" id="7" style="margin-left: 10px; border: 1px solid gray">
		<label id="a8" class="control-label leipiplugins-orgname" ></label><input type="text" id="8" style="margin-left: 10px; border: 1px solid gray">
		<label id="a9" class="control-label leipiplugins-orgname" ></label><input type="text" id="9" style="margin-left: 10px; border: 1px solid gray">
		<label id="a10" class="control-label leipiplugins-orgname" ></label><input type="text" id="10" style="margin-left: 10px; border: 1px solid gray">
		<label id="a11" class="control-label leipiplugins-orgname" ></label><input type="text" id="11" style="margin-left: 10px; border: 1px solid gray">
		<label id="a12" class="control-label leipiplugins-orgname" ></label><input type="text" id="12" style="margin-left: 10px; border: 1px solid gray">
		<label id="a13" class="control-label leipiplugins-orgname" ></label><input type="text" id="13" style="margin-left: 10px; border: 1px solid gray">
		<label id="a14" class="control-label leipiplugins-orgname" ></label><input type="text" id="14" style="margin-left: 10px; border: 1px solid gray">
		<label id="a15" class="control-label leipiplugins-orgname" ></label><input type="text" id="15" style="margin-left: 10px; border: 1px solid gray">
		<label id="a16" class="control-label leipiplugins-orgname" ></label><input type="text" id="16" style="margin-left: 10px; border: 1px solid gray">
		<label id="a17" class="control-label leipiplugins-orgname" ></label><input type="text" id="17" style="margin-left: 10px; border: 1px solid gray">
		<label id="a18" class="control-label leipiplugins-orgname" ></label><input type="text" id="18" style="margin-left: 10px; border: 1px solid gray">
		<label id="a19" class="control-label leipiplugins-orgname" ></label><input type="text" id="19" style="margin-left: 10px; border: 1px solid gray">
		<label id="a20" class="control-label leipiplugins-orgname" ></label><input type="text" id="20" style="margin-left: 10px; border: 1px solid gray">
		<!-- 多行文本框 -->
		&emsp;<label id="b0" class="control-label leipiplugins-orgname" ></label><textarea id="t0" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b1" class="control-label leipiplugins-orgname" ></label><textarea id="t1" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b2" class="control-label leipiplugins-orgname" ></label><textarea id="t2" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b3" class="control-label leipiplugins-orgname" ></label><textarea id="t3" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b4" class="control-label leipiplugins-orgname" ></label><textarea id="t4" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b5" class="control-label leipiplugins-orgname" ></label><textarea id="t5" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b6" class="control-label leipiplugins-orgname" ></label><textarea id="t6" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b7" class="control-label leipiplugins-orgname" ></label><textarea id="t7" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b8" class="control-label leipiplugins-orgname" ></label><textarea id="t8" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b9" class="control-label leipiplugins-orgname" ></label><textarea id="t9" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b10" class="control-label leipiplugins-orgname" ></label><textarea id="t10" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b11" class="control-label leipiplugins-orgname" ></label><textarea id="t11" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b12" class="control-label leipiplugins-orgname" ></label><textarea id="t12" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b13" class="control-label leipiplugins-orgname" ></label><textarea id="t13" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b14" class="control-label leipiplugins-orgname" ></label><textarea id="t14" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b15" class="control-label leipiplugins-orgname" ></label><textarea id="t15" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b16" class="control-label leipiplugins-orgname" ></label><textarea id="t16" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b17" class="control-label leipiplugins-orgname" ></label><textarea id="t17" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b18" class="control-label leipiplugins-orgname" ></label><textarea id="t18" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b19" class="control-label leipiplugins-orgname" ></label><textarea id="t19" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
		&emsp;<label id="b20" class="control-label leipiplugins-orgname" ></label><textarea id="t20" style="margin-left: 10px; margin-bottom: -11px; border: 1px solid gray"></textarea>
	</div>
</body>
</html>
